package com.ljx.itbbs.server.user.controller;


import com.ljx.itbbs.common.domain.vo.resp.ApiResult;
import com.ljx.itbbs.server.user.domain.entity.PermsEntity;
import com.ljx.itbbs.server.user.domain.vo.req.PermsCategoryUpdateReq;
import com.ljx.itbbs.server.user.domain.vo.req.PermsSaveReq;
import com.ljx.itbbs.server.user.domain.vo.req.PermsUpdateReq;
import com.ljx.itbbs.server.user.domain.vo.resp.PermsCategoryResp;
import com.ljx.itbbs.server.user.domain.vo.resp.PermsResp;
import com.ljx.itbbs.server.user.domain.vo.resp.PermsTree;
import com.ljx.itbbs.server.user.service.PermsCategoryService;
import com.ljx.itbbs.server.user.service.PermsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author LiJunXi
 * @since 2024-03-02
 */
@Api(tags = "权限接口")
@RestController
@RequestMapping("/perms")
public class PermsController {

    @Autowired
    private PermsService permsService;

    @Autowired
    private PermsCategoryService permsCategoryService;

    @ApiOperation("获取权限信息")
    @GetMapping("/info")
    public ApiResult<PermsResp> getPermsInfo(@RequestParam("permsId") Long permsId){

        return ApiResult.success(permsService.getPermsInfo(permsId));
    }

    @ApiOperation("保存权限")
    @PostMapping("/save")
    public ApiResult<Void> savePerms(@Valid @RequestBody PermsSaveReq req){
        permsService.savePerms(req);

        return ApiResult.success();
    }

    @ApiOperation("更新权限")
    @PutMapping("/update")
    public ApiResult<Void> updatePerms(@Valid @RequestBody PermsUpdateReq req){
        permsService.updatePerms(req);

        return ApiResult.success();
    }

    @ApiOperation("更新权限分类")
    @PutMapping("/category/update")
    public ApiResult<Void> updatePermsCategory(@Valid @RequestBody PermsCategoryUpdateReq req){
        permsCategoryService.updatePermsCategory(req);

        return ApiResult.success();
    }

    @ApiOperation("获取权限分类")
    @GetMapping("/category/list")
    public ApiResult<List<PermsCategoryResp>> getPermsCategory(){

        return ApiResult.success(permsCategoryService.getPermsCategory());
    }

    @ApiOperation("获取权限列表")
    @GetMapping("/list")
    public ApiResult<List<PermsTree>> getPermsList(){

        return ApiResult.success(permsService.getPermsList());
    }


}

